﻿using System;
using System.Resources;

namespace ImporterForm
{
    /// <summary>
    /// Implements code to assist in getting configuration information for the plug-in
    /// </summary>
    public class Config
    {
        #region Fields (10)

        /// <summary>
        /// Instance of the <see cref="ConfigReader"/> class to use with this instance of the <see cref="Config"/> class.
        /// </summary>
        private static ConfigReader _configReader = null;

        /// <summary>
        /// Instance of the <see cref="ResourceManager"/> class to use with this instance of the <see cref="Config"/> class.
        /// </summary>
        private static ResourceManager _resourceManager = null;

        /// <summary>
        /// Backing field for the <see cref="AitXmlElementNameParagraph"/> property.
        /// </summary>
        private string aitXmlElementNameParagraph;

        /// <summary>
        /// Backing field for the <see cref="AitXmlElementNameText"/> property.
        /// </summary>
        private string aitXmlElementNameText;

        /// <summary>
        /// Backing field for the <see cref="DefaultParagraphStyleId"/> property.
        /// </summary>
        private int defaultParagraphStyleId;

        /// <summary>
        /// Backing field for the <see cref="DocBookDefaultNamespace"/> property.
        /// </summary>
        private string docBookDefaultNamespace = null;

        /// <summary>
        /// Backing field for the <see cref="MainFormBorderStyle"/> property.
        /// </summary>
        private System.Windows.Forms.FormBorderStyle mainFormBorderStyle;

        /// <summary>
        /// Backing field for the <see cref="MainFormMaximizeBox"/> property.
        /// </summary>
        private bool mainFormMaximizeBox = false;

        /// <summary>
        /// Backing field for the <see cref="MainFormStartPosition"/> property.
        /// </summary>
        private System.Windows.Forms.FormStartPosition mainFormStartPosition;

        /// <summary>
        /// Backing field for the <see cref="VariableNameDcmiTitle"/> property.
        /// </summary>
        private string variableNameDcmiTitle = null;

        #endregion Fields

        #region Constructors (1)

        /// <summary>
        /// Initializes a new instance of the <see cref="Config"/> class.
        /// </summary>
        public Config()
        {
            _resourceManager = new ResourceManager("", typeof(ImporterForm).Assembly);
            _configReader = new ConfigReader();
            ReadConfiguration();
        }

        #endregion Constructors

        #region Properties (8)

        /// <summary>
        /// Gets the name of the Author-it XML element that represents a paragraph.
        /// </summary>
        public string AitXmlElementNameParagraph { get { return aitXmlElementNameParagraph; } }

        /// <summary>
        /// Gets the name of the Author-it XML element that contains the text for a topic.
        /// </summary>
        public string AitXmlElementNameText { get { return aitXmlElementNameText; } }

        /// <summary>
        /// Gets the ID for the default paragraph style in the library
        /// </summary>
        public int DefaultParagraphStyleId { get { return defaultParagraphStyleId; } }

        /// <summary>
        /// Gets the default namespace for DocBook XML.
        /// </summary>
        public string DocBookDefaultNamespace { get { return docBookDefaultNamespace; } }

        /// <summary>
        /// Gets the border style to use when displaying the main form.
        /// </summary>
        public System.Windows.Forms.FormBorderStyle MainFormBorderStyle { get { return mainFormBorderStyle; } }

        /// <summary>
        /// Gets a value that specifies whether to show the maximize box on the main form.
        /// </summary>
        public bool MainFormMaximizeBox { get { return mainFormMaximizeBox; } }

        /// <summary>
        /// Gets a value that specifies the start position for the main form.
        /// </summary>
        public System.Windows.Forms.FormStartPosition MainFormStartPosition { get { return mainFormStartPosition; } }

        /// <summary>
        /// Gets the name of the variable that stores the topic title.
        /// </summary>
        public string VariableNameDcmiTitle { get { return variableNameDcmiTitle; } }

        #endregion Properties

        #region Methods (1)

        // Public Methods (1) 

        /// <summary>
        /// Reads the configuration file for the plug-in and sets properties for this instance of <see cref="Config"/>.
        /// </summary>
        public void ReadConfiguration()
        {
            variableNameDcmiTitle = _configReader.GetSetting(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.VarName_DCMI_Title));
            docBookDefaultNamespace = _configReader.GetSetting(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.DocBookDefaultNamespace));
            defaultParagraphStyleId = _configReader.GetSettingAsInt(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.DefaultParagraphStyleId));
            mainFormBorderStyle = (System.Windows.Forms.FormBorderStyle)Enum.Parse(typeof(System.Windows.Forms.FormBorderStyle), _configReader.GetSetting(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.MainFormBorderStyle)));
            mainFormMaximizeBox = _configReader.GetSettingAsBool(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.MainFormMaximizeBox));
            mainFormStartPosition = (System.Windows.Forms.FormStartPosition)Enum.Parse(typeof(System.Windows.Forms.FormStartPosition), _configReader.GetSetting(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.MainFormStartPosition)));
            aitXmlElementNameText = _configReader.GetSetting(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.AitXmlElementNameText));
            aitXmlElementNameParagraph = _configReader.GetSetting(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.AitXmlElementNameParagraph));
        }

        #endregion Methods
    }
}